//
//  OperationButton.swift
//  GreenDeal
//
//  Created by Moennig Q on 8/12/2022.
//

import UIKit

class OperationButton: BaseButton {
    //操作按钮的高度
    static let height: CGFloat = 44
    static let bottomMargin: CGFloat = -(UIDevice.getBottomAreaHeight() + 10)
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.initView()
    }
    convenience init(_ title: String,enabled: Bool = true, backColor: UIColor? = nil) {
        self.init(frame: CGRect.zero)
        self.setTitle(title, for: UIControl.State.normal)
        if enabled {
            self.enableBtn(backColor)
        }else{
            self.disableBtn(backColor)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func initView() {
        self.layer.cornerRadius = Constant.StandardCornerRadius
        self.clipsToBounds = true
        self.setTitle("", for: UIControl.State.normal)
        self.setTitleColor(.white, for: UIControl.State.normal)
        self.setFont(R.font.interMedium(size: 17))
    }
    func enableBtn(_ backColor: UIColor? = nil){
        let color = (backColor == nil ? UIColor(hexStr: Constant.ThemeColorHexStr) : backColor!)
        self.backgroundColor = color
        self.isEnabled = true
    }
    func disableBtn(_ backColor: UIColor? = nil){
        let color = (backColor == nil ? UIColor(hexStr: "#D9D9D9") : backColor!)
        
        self.backgroundColor = color
        self.isEnabled = false
    }
}
